﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/23/2009
 * Time: 12:32 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Buaya.Model;

namespace Buaya.Gui
{
	/// <summary>
	/// Description of LoanEmployeeForm.
	/// </summary>
	public partial class LoanEmployeeForm : BaseForm
	{
		public LoanEmployeeForm() : this(new Loan())
		{
			
		}
		
		public LoanEmployeeForm(Loan l)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			Util.SwfUtility.SetupComboBox(comboBoxEmployee, SessionFacade.FindAllEmployees(), "Id", "Name");
			Util.SwfUtility.SetupComboBox(comboBoxType, SessionFacade.FindAllLoanTypes(), "Id", "Name");
			Model = l;
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			Loan l = Model as Loan;
		}
		
		void ButtonOkClick(object sender, EventArgs e)
		{
			Loan l = Model as Loan;
			l.Employee = (comboBoxEmployee.DataSource as IList<Employee>)[comboBoxEmployee.SelectedIndex];
			l.Type = (comboBoxType.DataSource as IList<LoanType>)[comboBoxType.SelectedIndex];
			DialogResult = DialogResult.OK;
			Close();
		}
		
		void ButtonCancelClick(object sender, EventArgs e)
		{
			Close();
		}
	}
}
